package be.kuleuven.cs.mop.domain.exceptions;

public class TaskManagerException extends Exception {
	
	private int errorCode;
	
	private static final long serialVersionUID = 1L;
	public static final int USER_INVALID_NAME = 0;
	public static final int INVALID_RESOURCE_TYPE = 1;
	public static final int PROJECT_INVALID_DESCRIPTION = 2;
	public static final int RESOURCE_RESERVATION_CONFLICT = 3;
	public static final int INVALID_USER = 4;
	public static final int NO_USER_LOGGED_IN = 5;
	public static final int INVALID_DATE = 6;
	public static final int INVALID_DURATION = 7;
	public static final int BUSINESS_RULE_VIOLATION_CAN_NOT_BE_HANDLED_RECURSIVELY = 8;
	public static final int RESOURCE_INVALID_DESCRIPTION = 9;
	public static final int INVALID_SCHEDULE_PARAMETERS = 10;
	public static final int RESERVATION_DOES_NOT_EXIST = 11;
	public static final int TASK_INVALID_RESOURCES = 12;
	public static final int TASK_INVALID_DESCRIPTION = 13;
	public static final int TASK_INVALID_DEPENDENCIES_SCHEDULE = 14;
	public static final int TASK_DEPENDENCY_LOOP = 15;
	public static final int INVALID_TASK_TYPE = 16;
	public static final int INVALID_TASK = 17;
	public static final int TASK_ALREADY_ASSIGNED_TO_PROJECT = 18;
	public static final int INVALID_PROJECT = 19;
	public static final int SAFE_REMOVAL_IMPOSSIBLE = 20;
	public static final int USER_ALREADY_EXISTS = 21;
	public static final int PROJECT_ALREADY_EXISTS = 22;
	public static final int RESOURCE_ALREADY_EXISTS = 23;
	public static final int INVALID_RESOURCE = 24;
	public static final int TASK_CAN_NOT_BE_MODIFIED = 25;
	public static final int TASK_HAS_DEPENDANTS = 26;
	public static final int INVALID_TASK_STATUS = 27;
	public static final int INVALID_FIELD_VALUE_TYPE = 28;
	public static final int INVALID_LOWERLIMIT_UPPERLIMIT_COMBINATION = 29;
	public static final int FIELDS_DO_NOT_SATISFY_TASKTYPE_REQUIREMENTS = 30;
	public static final int FIELD_VALUE_CAN_NOT_BE_NULL = 31;
	public static final int TASK_DOES_NOT_MEET_HELPER_USER_REQUIREMENTS = 32;
	public static final int INVALID_USER_TYPE = 33;
	public static final int USER_ALREADY_INVITED = 35;
	public static final int USER_OWNS_THIS_TASK = 36;
	public static final int TASK_INVITATION_MAXIMUM = 37;
	public static final int INVALID_USER_TYPE_HELPER = 38;
	public static final int INVALID_TASK_SCHEDULE = 39;
	public static final int TASKTYPE_DOES_NOT_ALLOW_OWNER_TYPE = 40;
	public static final int TASK_DOES_NOT_BELONG_TO_PROJECT = 41;
	public static final int TASK_OWNER_INVITATION_ERROR = 42;
	public static final int INVITATION_CONSTRAINTS_VIOLATED = 43;
	public static final int UPPER_LIMIT_OF_RESERVED_RESOURCES_REACHED_FOR_RESOURCETYPE = 44;
	public static final int USER_TYPE_INVALID_NAME = 45;
	public static final int TASK_TYPE_INVALID_NAME = 46;
	public static final int RESOURCE_TYPE_INVALID_NAME = 47;
	public static final int RESOURCE_NOT_REQUIRED_BY_TASK = 48;
	public static final int TASK_CAN_NOT_BE_COMPLETED_AFTER_DEADLINE_OR_BEFORE_START = 49;
	public static final int DEADLINE_EXPIRED = 50;
	public static final int TASK_DOES_NOT_MEET_RESOURCE_RESERVATION_REQUIREMENTS = 51;
	public static final int RESOURCE_RESERVATIONS_OVERLAP_NOT_LONG_ENOUGH = 52;
	public static final int NOT_ALLOWED_TO_MODIFY_INVITATION = 53;
	public static final int FIELD_TYPE_CAN_NOT_BE_NULL = 54;
	

	public TaskManagerException(int errorCode) {
		this.errorCode = errorCode;
	}
	
	/**
	 * Returns the error code of this exception
	 */
	public int getErrorCode(){ return errorCode; };
	
	/**
	 * Returns a string representation of this exception, based on the error code of this exception
	 */
	@Override
	public String getMessage() {
		switch(getErrorCode()) {
			case USER_INVALID_NAME:  return "Invalid name for a User";
			case INVALID_RESOURCE_TYPE: return "Invalid Resource Type";
			case PROJECT_INVALID_DESCRIPTION:  return "Invalid Description for a Project";
			case RESOURCE_RESERVATION_CONFLICT:  return "Reservation in conflict with existing reservations";
			case INVALID_USER: return "Invalid User";
			case NO_USER_LOGGED_IN: return "There is no User logged in";
			case INVALID_DATE: return "Invalid Date";
			case INVALID_DURATION: return ("Invalid Duration");
			case RESOURCE_INVALID_DESCRIPTION: return "Invalid description for a Resource";
			case INVALID_SCHEDULE_PARAMETERS: return "Conflicting parameters for a Schedule";
			case RESERVATION_DOES_NOT_EXIST: return "This Reservation does not exist in the system";
			case TASK_INVALID_RESOURCES: return "Invalid Resources for a Task";
			case TASK_INVALID_DESCRIPTION: return "Invalid Description for a Task";
			case TASK_INVALID_DEPENDENCIES_SCHEDULE: return "Conflict in the dependencies/schedule combination";
			case INVALID_TASK_TYPE: return "Invalid task type";
			case TASK_DEPENDENCY_LOOP: return "A loop was detected in the supplied dependencies";
			case INVALID_TASK : return "Invalid Task";
			case TASK_ALREADY_ASSIGNED_TO_PROJECT : return "This Task was already assigned to a Project";
			case INVALID_PROJECT : return "Invalid Project";
			case USER_ALREADY_EXISTS : return "User already exists";
			case PROJECT_ALREADY_EXISTS : return "Project already exists";
			case RESOURCE_ALREADY_EXISTS : return "Resource already exists";
			case INVALID_FIELD_VALUE_TYPE : return "The type of value you supplied does not match the FieldType representation class";
			case INVALID_LOWERLIMIT_UPPERLIMIT_COMBINATION : return "Invalid lower and upper limit combination";
			case FIELDS_DO_NOT_SATISFY_TASKTYPE_REQUIREMENTS : return "The supplied fields do not match the TaskType field requirements";
			case TASK_DOES_NOT_MEET_HELPER_USER_REQUIREMENTS : return "This task does not currently meet it's helper user requirements.";
			case TASK_DOES_NOT_MEET_RESOURCE_RESERVATION_REQUIREMENTS : return "This task does not currently meet it's reserved resources requirements.";
			case INVALID_USER_TYPE : return "Invalid UserType";
			case USER_ALREADY_INVITED : return "User is already invited for this task";
			case USER_OWNS_THIS_TASK : return "The User owns this task and is thus not allowed to be invitated for this task";
			case TASK_INVITATION_MAXIMUM : return "The maximum number of invitations for this tasktype is reached";
			case INVALID_USER_TYPE_HELPER : return "a user is invited to a task that does not allow a helper user of that type";
			case INVALID_TASK_SCHEDULE : return "This schedule is not valid for a Task";
			case TASKTYPE_DOES_NOT_ALLOW_OWNER_TYPE : return "The TaskType you supplied does not allow an owner of this UserType";
			case TASK_DOES_NOT_BELONG_TO_PROJECT : return "The Task does not belong to a Project";
			case BUSINESS_RULE_VIOLATION_CAN_NOT_BE_HANDLED_RECURSIVELY : return "The Business Rule Violation cause by this task state update does not match the type that may be solved recursively.";
			case RESOURCE_NOT_REQUIRED_BY_TASK : return "The resource you tried to reserve is not required by the Task you supplied";
			case UPPER_LIMIT_OF_RESERVED_RESOURCES_REACHED_FOR_RESOURCETYPE : return "The upper limit of reserved resources, as defined in the TaskType, has already been met for this Task.";
			case USER_TYPE_INVALID_NAME : return "The name is invalid or already in use by an other user type";
			case TASK_TYPE_INVALID_NAME : return "The name is invalid or already in use by an other task type";
			case RESOURCE_TYPE_INVALID_NAME : return "The name is invalid or already in use by an other resource type";
			case TASK_CAN_NOT_BE_COMPLETED_AFTER_DEADLINE_OR_BEFORE_START : return "Task can not be completed at this time";
			case DEADLINE_EXPIRED : return "The deadline of the task is expired. This action can not be performed";
			case RESOURCE_RESERVATIONS_OVERLAP_NOT_LONG_ENOUGH : return "Adding this reservation would result in a resource reservations overlap that is not long enough to complete this Task, considering its duration and the Task's schedule.";
			case FIELD_VALUE_CAN_NOT_BE_NULL : return "The value of a Field can not be null";
			case NOT_ALLOWED_TO_MODIFY_INVITATION : return "The user is not allowed to modify the invitation";
			case FIELD_TYPE_CAN_NOT_BE_NULL : return "The type of a Field can not be null";
			case TASK_CAN_NOT_BE_MODIFIED : return "The status of the Task does not allow modification";
			case INVITATION_CONSTRAINTS_VIOLATED : return "The invitation constraints for this task are violated by this action";
			case SAFE_REMOVAL_IMPOSSIBLE : return "Safe removal is impossible";
			case INVALID_RESOURCE : return "Invalid resource";
			case TASK_HAS_DEPENDANTS : return "Task has dependants";
			case INVALID_TASK_STATUS : return "Invalid task status";
			case TASK_OWNER_INVITATION_ERROR  : return "The current user is the owner of the given task";
			default:  return "Could not find a specific explanation regarding the error code of this exception";
		}
	}
}
